package listener;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import dto.UserDTO;

public class Listener implements HttpSessionListener {
	@SuppressWarnings("unchecked")
	private Set set=new HashSet();

	public void sessionCreated(HttpSessionEvent arg0) {
		arg0.getSession().getServletContext().setAttribute("set",set);

	}

	@SuppressWarnings("unchecked")
	public void sessionDestroyed(HttpSessionEvent arg0) {
		set=(Set) arg0.getSession().getServletContext().getAttribute("set");
		UserDTO user=(UserDTO) arg0.getSession().getAttribute("USER");
		if(null!=set){
			if(set.size()!=0){
				if(null!=user){
					set.remove(user.getUserName());
					arg0.getSession().getServletContext().setAttribute("set",set);
					arg0.getSession().getServletContext().setAttribute("count",set.size());
				}
			}
		}
	}
}
